/*
 * @Author: maomao
 * @Date: 2021-04-19 09:44:39
 * @Description: 
 * @FilePath: \his-dictionary-web\src\utils\view-tool.ts
 */
import { PageInfo } from "@/api/api_catalogclient";
import { LoadOptions } from "devextreme/data/load_options";
import { ViewTool as ViewToolBase } from '../framework/utils/view-tool';


/**视图工具 */
export class ViewTool extends ViewToolBase {

  /**
   * 合并分页信息
   * @param opt 选项
   * @param pageInfo 分页信息
   */
  static assignPageInfo(opt: LoadOptions, pageInfo: PageInfo): PageInfo {
    if (!opt)
      return pageInfo;
    return Object.assign(
      pageInfo, {
      index: opt.skip / opt.take
    });
  }

  /**
   * 获取加载结果
   * @param value 值
   * @param pageinfo 分页信息
   */
  static getLoadResult<T>(value: T, pageinfo: PageInfo) {
    return {
      data: value,
      totalCount: pageinfo.count
    };
  }
}